package application;

import javax.swing.ImageIcon;
import gui.EnterNameFrame;
import gui.GameFrame;
import gui.StartGame;

public class GameManager {
		
	public static boolean DEBUG;
	private StartGame _StartGame;
	private GameFrame _GameFrame;
	private HighScoreTable _highScoreTable;
	
	public GameManager(HighScoreTable scoreTable){
		this._StartGame = new StartGame(this);
		this._GameFrame = null;
		this._highScoreTable = scoreTable;
	}
	/**
	 * called when game is over
	 * @param get_score
	 */
	public void gameOver(int get_score) {
		this._GameFrame.stopTimers();
		this._GameFrame.setVisible(false);
		new EnterNameFrame(this);
	}
	/**
	 * starts a game with a Predator snake
	 */
	public void startPredetorGame() {
		ImageIcon[] tImageArray = new ImageIcon[3];
		tImageArray[0] = new ImageIcon("PredSnakeHead.png");
		tImageArray[1] = new ImageIcon("PredSnakeBody.png");
		tImageArray[2] = new ImageIcon("grass.png");
		this._GameFrame = new GameFrame(tImageArray,this,"predator");
		this._StartGame.setVisible(false);
	}
	/**
	 * starts a game with an Ornamental snake
	 */
	public void startOrnamentalGame() {
		ImageIcon[] tImageArray = new ImageIcon[3];
		tImageArray[0] = new ImageIcon("o_Snake_Head.png");
		tImageArray[1] = new ImageIcon("o_Snake_Body.png");
		tImageArray[2] = new ImageIcon("Sand_copy.png");
		this._GameFrame = new GameFrame(tImageArray,this,"ornamental");
		this._StartGame.setVisible(false);
	}
	/**
	 * starts a game with an Ice Age snake
	 */
	public void startIceAgeGame() {
		ImageIcon[] tImageArray = new ImageIcon[3];
		tImageArray[0] = new ImageIcon("w_Snake_Head.png");
		tImageArray[1] = new ImageIcon("w_Snake_Body.png");
		tImageArray[2] = new ImageIcon("snow_back.png");
		//tImageArray[2] = new ImageIcon("bar-refaeli-8 copy.png");
		this._GameFrame =  new GameFrame(tImageArray,this,"iceage");
		this._StartGame.setVisible(false);
	}
	
	public void startAdultVerGame() {
		ImageIcon[] tImageArray = new ImageIcon[3];
		tImageArray[0] = new ImageIcon("w_Snake_Head.png");
		tImageArray[1] = new ImageIcon("w_Snake_Body.png");
		//tImageArray[2] = new ImageIcon("snow_back.png");
		tImageArray[2] = new ImageIcon("bar-refaeli-8 copy.png");
		this._GameFrame =  new GameFrame(tImageArray,this,"iceage");
		this._StartGame.setVisible(false);
	}
	
	/**
	 * speeds up snake to double speed
	 */
	public void speedUpSnake(){
		this._GameFrame.speedUpSnake();
	}
	/**
	 * slows down snake to half speed
	 */
	public void slowDownSnake(){
		this._GameFrame.slowDownSnake();
	}
	/**
	 * prints message if DEBUG == true
	 * @param msg
	 */
	public static void print(String msg){
		if(DEBUG)
			System.out.println(msg);
	}
	/**
	 * updates score on the game frame
	 */
	public void updateScore() {
		this._GameFrame.updateScore();
	}
	/**
	 * getter
	 * @return
	 */
	public StartGame get_StartGame() {
		return this._StartGame;
	}
	/**
	 * getter
	 * @return
	 */
	public HighScoreTable get_highScoreTable() {
		return _highScoreTable;
	}
	/**
	 * getter
	 * @return
	 */
	public String getScore(){
		return this._GameFrame.getScore();
	}
	/**
	 * main methods
	 * @param args
	 */
	public void repaint(){
		this._GameFrame.repaintPanel();
	}
	public static void main(String[] args) {
		/*if(args.length > 0)
			DEBUG = Boolean.parseBoolean(args[0]);
		else DEBUG = false;*/
		DEBUG = false;
		print("debug mod");
		HighScoreTable scoreTable = XmlEncodeToFile.readFromFile();
		new GameManager(scoreTable);
	}
	public void addFood() {
		this._GameFrame.addFood();
	}

}
